﻿using System.Reflection;

namespace Borg
{
    internal class PlugPlugsTask : Task<ExtensionInfo>
    {
        private readonly ExtensionInfo _ei;
        private readonly ExtensionInfo _ignoreExt;

        private readonly bool _isManual;

        public override string Name
        {
            get
            {
                return _ei == null
                    ? string.Format("PlugPlugs({0})", obj.Name)
                    : string.Format("PlugPlugs({0}, {1})", obj.Name, _ei.Name);
            }
        }

        public PlugPlugsTask(ExtensionInfo obj, ExtensionInfo ei, bool isManual,
            uint taskGroupId, Assembly initiator, ExtensionInfo ignoreExt)
            : base(obj, taskGroupId, initiator)
        {
            _ei = ei;
            _isManual = isManual;
            _ignoreExt = ignoreExt;
        }

        public override void Execute()
        {
            if (_ei == null)
                obj.InternalPlugPlugs(_isManual, taskGroupId, initiator, _ignoreExt);
            else
                _ei.InternalPlugInSlots(obj, _isManual, taskGroupId, initiator);
        }

        public override string ToString()
        {
            var str = _ei != null
                          ? string.Format("{0}: {1}.InternalPlugPlugs({2}, {3})",
                                          (object)taskGroupId, (object)obj, (object)_ei, (object)(_isManual ? 1 : 0))
                          : string.Format("{0}: {1}.InternalPlugPlugs({2})",
                                          taskGroupId, obj, _isManual ? 1 : 0);

            return str;
        }
    }
}

